//
//  M4MineViewController.swift
//  M4
//
//  Created by YuChuang on 2024/8/6.
//

import UIKit

class M4MineViewController: M4BaseViewController {
    
    @IBOutlet weak var M4UserNickName: UILabel!
    
    @IBOutlet weak var M4TopView: UIView!
    
    @IBOutlet weak var M4BottomView: UIView!
    
    
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.navigationBar.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.navigationBar.isHidden = false
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        var phone = M4UserDataManager.m4UserShare.M4UserMobile
        let front = (phone as NSString).substring(with: NSMakeRange(0, 3))
        let back = (phone as NSString).substring(with: NSMakeRange(phone.count-4, 4))
        M4UserNickName.text = "Hola~ " + front + "***" + back
        M4TopView.layer.cornerRadius = 2
        M4TopView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
        M4BottomView.layer.cornerRadius = 2
        M4BottomView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
    }


    @IBAction func M4MineButtonClick(_ sender: UIButton) {
        var page = M4BaseViewController()
        if sender.tag == 10 {
            page = M4HistoryViewController()
        }
        else if sender.tag == 11 {
            page = M4UserBankViewController()
        }
        else if sender.tag == 12 {
            page = M4SuggestionViewController()
        }
        else if sender.tag == 13 {
            page = M4AboutUsViewController()
        }
        else if sender.tag == 14 {
            page = M4HtmlWebViewController()
            (page as! M4HtmlWebViewController).M4WebTitle = "Privacidad"
            (page as! M4HtmlWebViewController).M4WebUrl = M4NetworkAPI.m4htmlPath.rawValue + "/nafvsdahgv"
            (page as! M4HtmlWebViewController).M4OpenPrivacy = true
        }
        else if sender.tag == 15 {
            let htmlVC = M4HtmlWebViewController()
            htmlVC.M4WebTitle = "Acuerdo de préstamo"
            htmlVC.M4WebUrl = M4NetworkAPI.m4htmlPath.rawValue + "/asdasd?vcxoPPo=\(M4UserDataManager.m4UserShare.M4Token)&sesaPPOs=\(0)"
            self.navigationController?.pushViewController(htmlVC, animated: true)
            sender.M4EventUnavailable = false
            return
        }
        self.navigationController?.pushViewController(page, animated: true)
        sender.M4EventUnavailable = false
    }
    

}
